package com.csot.ry.controller;

import com.csot.ry.domain.TCitySegment;
import com.csot.ry.service.ITCitySegmentService;
import com.csot.ry.service.ITDetectJobService;
import com.csot.common.core.controller.BaseController;
import com.csot.common.core.domain.AjaxResult;
import com.csot.common.core.page.TableDataInfo;
import com.csot.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 城市ip段Controller
 * 
 * @author 刘沙
 * @date 2022-05-31
 */
@RestController
@RequestMapping("/ipmanagement/detecttask")
public class DetectTaskController extends BaseController {

	@Autowired
	private ITCitySegmentService tCitySegmentService;

	@Autowired
	private ITDetectJobService tDetectJobService;

	/**
	 * 查询城市ip段列表
	 */
	@PreAuthorize("@ss.hasPermi('ipmanagement:detecttask:list')")
	@GetMapping("/list")
	public TableDataInfo list(TCitySegment tCitySegment) {
		startPage();
		List<TCitySegment> list = tCitySegmentService.selectTCitySegmentList(tCitySegment);
		return getDataTable(list);
	}

	/**
	 * 探活ip段
	 */
	@PreAuthorize("@ss.hasPermi('ipmanagement:detecttask:task')")
//	@Log(title = "探活ip段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult detecttask(@PathVariable Long[] ids) {
		return toAjax(tDetectJobService.JobByIds(ids));
	}

	/**
	 * 探活ip段
	 */
	@PreAuthorize("@ss.hasPermi('ipmanagement:detecttask:taskall')")
	@PostMapping("/taskall")
	public AjaxResult detecttaskall() {
		return toAjax(tDetectJobService.joball());
	}

	/**
	 * 更新探活返回的接口
	 */
	@PostMapping("/updateTask")
	public AjaxResult updateTask(@RequestBody String updateTask) {
		try {
			return toAjax(tDetectJobService.updateTask(java.net.URLDecoder.decode(updateTask,"UTF-8")));
		} catch (UnsupportedEncodingException e) {
			throw new ServiceException(e.getMessage());
		}

	}

}
